package me.fung.rem.app.content.card

import androidx.compose.foundation.background
import androidx.compose.runtime.Composable
import androidx.compose.foundation.layout.*
import androidx.compose.material.Card
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.setValue
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.input.pointer.PointerEventType
import androidx.compose.ui.input.pointer.onPointerEvent
import androidx.compose.ui.unit.dp

// 卡片
@OptIn(ExperimentalComposeUiApi::class)
@Composable
fun card(
    modifier: Modifier = Modifier,
    content: @Composable ColumnScope.() -> Unit
) {
    var select by remember { mutableStateOf(value = false) }
    Box(
        modifier = Modifier.padding(10.dp).size(200.dp, 150.dp)
            .onPointerEvent(PointerEventType.Enter) { select = true }
            .onPointerEvent(PointerEventType.Exit) { select = false }
    ) {
        Card(
            elevation = 20.dp,
            modifier = modifier
        ) {
            Box(
                modifier = Modifier.align(Alignment.Center)
                    .background(color = if (select) Color(0xFFEEEEEE) else Color.White)
            ) {
                Column(
                    modifier = Modifier.fillMaxSize(),
                    verticalArrangement = Arrangement.Center,
                    horizontalAlignment = Alignment.CenterHorizontally
                ) {
                    content()
                }
            }
        }
    }
}
